package db

import (
	"context"

	"github.com/opentracing/opentracing-go"
	"github.com/opentracing/opentracing-go/log"
)

type OpenTelemetryReceiver struct {
	tracer opentracing.Tracer
}

func (o *OpenTelemetryReceiver) Event(eventName string) {

}

func (o *OpenTelemetryReceiver) EventKv(eventName string, kvs map[string]string) {

}

func (o *OpenTelemetryReceiver) EventErr(eventName string, err error) error {

	return err
}

func (o *OpenTelemetryReceiver) EventErrKv(eventName string, err error, kvs map[string]string) error {

	return err
}

func (o *OpenTelemetryReceiver) Timing(eventName string, nanoseconds int64) {

}

func (o *OpenTelemetryReceiver) TimingKv(eventName string, nanoseconds int64, kvs map[string]string) {

}

func (o *OpenTelemetryReceiver) SpanStart(ctx context.Context, eventName, query string) context.Context {
	span, ctx := opentracing.StartSpanFromContext(ctx, eventName)
	span.LogFields(log.String("db.statement", query))
	return ctx
}

func (o *OpenTelemetryReceiver) SpanError(ctx context.Context, err error) {
	span := opentracing.SpanFromContext(ctx)
	if span != nil {
		span.SetTag("error", true)
		span.SetTag("error.message", err.Error())
	}
}

func (o *OpenTelemetryReceiver) SpanFinish(ctx context.Context) {
	span := opentracing.SpanFromContext(ctx)
	if span != nil {
		span.Finish()
	}
}
